﻿<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"
             xmlns:System="clr-namespace:System;assembly=mscorlib"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Style TargetType="toolkit:BusyIndicator">
        <Setter Property="BusyContent" Value="Please wait..."/>
        <Setter Property="IsTabStop" Value="False"/>
        <Setter Property="OverlayStyle">
            <Setter.Value>
                <Style TargetType="Rectangle">
                    <Setter Property="Fill" Value="DarkGray"/>
                    <Setter Property="Opacity" Value="0.5"/>
                </Style>
            </Setter.Value>
        </Setter>
        <Setter Property="DisplayAfter" Value="00:00:00.1"/>
        <Setter Property="HorizontalAlignment" Value="Stretch"/>
        <Setter Property="VerticalAlignment" Value="Stretch"/>
        <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
        <Setter Property="VerticalContentAlignment" Value="Stretch"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="toolkit:BusyIndicator">
                    <Grid>
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="VisibilityStates">
                                <VisualState x:Name="Hidden">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.001" Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="busycontent">
                                            <DiscreteObjectKeyFrame KeyTime="00:00:00">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <Visibility>Collapsed</Visibility>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.001" Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="overlay">
                                            <DiscreteObjectKeyFrame KeyTime="00:00:00">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <Visibility>Collapsed</Visibility>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Visible">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.001" Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="busycontent">
                                            <DiscreteObjectKeyFrame KeyTime="00:00:00">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <Visibility>Visible</Visibility>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.001" Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="overlay">
                                            <DiscreteObjectKeyFrame KeyTime="00:00:00">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <Visibility>Visible</Visibility>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                            <VisualStateGroup x:Name="BusyStatusStates">
                                <VisualState x:Name="Idle">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.001" Storyboard.TargetProperty="(Control.IsEnabled)" Storyboard.TargetName="content">
                                            <DiscreteObjectKeyFrame KeyTime="00:00:00">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <System:Boolean>True</System:Boolean>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="WaitingAnimationGrid">
                                            <DiscreteObjectKeyFrame KeyTime="0">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <Visibility>Collapsed</Visibility>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Busy">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.001" Storyboard.TargetProperty="(Control.IsEnabled)" Storyboard.TargetName="content">
                                            <DiscreteObjectKeyFrame KeyTime="00:00:00">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <System:Boolean>False</System:Boolean>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                        <DoubleAnimation Storyboard.TargetName="WaitGridAnimation" Storyboard.TargetProperty="(Grid.RenderTransform).(RotateTransform.Angle)" From="0" To="-360" Duration="0:0:1" RepeatBehavior="Forever"/>
                                        <DoubleAnimation Storyboard.TargetName="Ellipse1" Storyboard.TargetProperty="(Ellipse.Opacity)" From="1" To="0" Duration="0:0:0.5" RepeatBehavior="Forever" BeginTime="0:0:0.0625"/>
                                        <DoubleAnimation Storyboard.TargetName="Ellipse3" Storyboard.TargetProperty="(Ellipse.Opacity)" From="1" To="0" Duration="0:0:0.5" RepeatBehavior="Forever" BeginTime="0:0:0.1875"/>
                                        <DoubleAnimation Storyboard.TargetName="Ellipse5" Storyboard.TargetProperty="(Ellipse.Opacity)" From="1" To="0" Duration="0:0:0.5" RepeatBehavior="Forever" BeginTime="0:0:0.3125"/>
                                        <DoubleAnimation Storyboard.TargetName="Ellipse7" Storyboard.TargetProperty="(Ellipse.Opacity)" From="1" To="0" Duration="0:0:0.5" RepeatBehavior="Forever" BeginTime="0:0:0.4375"/>
                                        <DoubleAnimation Storyboard.TargetName="Ellipse0" Storyboard.TargetProperty="(Ellipse.Opacity)" From="1" To="0" Duration="0:0:0.5" RepeatBehavior="Forever"/>
                                        <DoubleAnimation Storyboard.TargetName="Ellipse2" Storyboard.TargetProperty="(Ellipse.Opacity)" From="1" To="0" Duration="0:0:0.5" RepeatBehavior="Forever" BeginTime="0:0:0.125"/>
                                        <DoubleAnimation Storyboard.TargetName="Ellipse4" Storyboard.TargetProperty="(Ellipse.Opacity)" From="1" To="0" Duration="0:0:0.5" RepeatBehavior="Forever" BeginTime="0:0:0.25"/>
                                        <DoubleAnimation Storyboard.TargetName="Ellipse6" Storyboard.TargetProperty="(Ellipse.Opacity)" From="1" To="0" Duration="0:0:0.5" RepeatBehavior="Forever" BeginTime="0:0:0.375"/>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="WaitingAnimationGrid">
                                            <DiscreteObjectKeyFrame KeyTime="0">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <Visibility>Visible</Visibility>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <ContentControl x:Name="content" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/>
                        <Rectangle x:Name="overlay" Style="{TemplateBinding OverlayStyle}"/>
                        <ContentPresenter x:Name="busycontent">
                            <Grid x:Name="WaitingAnimationGrid" Background="DarkGray" Opacity="0.5" >
                                <Grid x:Name="WaitGridAnimation" RenderTransformOrigin="0.5,0.5" Margin="2" MaxWidth="130" MaxHeight="130" Background="{x:Null}">
                                    <Grid.RenderTransform>
                                        <RotateTransform Angle="0"/>
                                    </Grid.RenderTransform>
                                    <Grid>
                                        <Grid.RowDefinitions>
                                            <RowDefinition/>
                                            <RowDefinition/>
                                            <RowDefinition/>
                                            <RowDefinition/>
                                            <RowDefinition/>
                                        </Grid.RowDefinitions>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition/>
                                            <ColumnDefinition/>
                                            <ColumnDefinition/>
                                            <ColumnDefinition/>
                                            <ColumnDefinition/>
                                        </Grid.ColumnDefinitions>
                                        <Ellipse  Grid.Row="0" Grid.Column="2" x:Name="Ellipse1" MinWidth="1" MinHeight="1" Fill="DarkGreen"/>
                                        <Ellipse  Grid.Row="2" Grid.Column="4" x:Name="Ellipse3" MinWidth="1" MinHeight="1" Fill="DarkGreen"/>
                                        <Ellipse  Grid.Row="4" Grid.Column="2" x:Name="Ellipse5" MinWidth="1" MinHeight="1" Fill="DarkGreen"/>
                                        <Ellipse  Grid.Row="2" Grid.Column="0" x:Name="Ellipse7" MinWidth="1" MinHeight="1" Fill="DarkGreen"/>
                                    </Grid>
                                    <Grid RenderTransformOrigin="0.5,0.5">
                                        <Grid.RenderTransform>
                                            <RotateTransform Angle="-45"/>
                                        </Grid.RenderTransform>
                                        <Grid.RowDefinitions>
                                            <RowDefinition/>
                                            <RowDefinition/>
                                            <RowDefinition/>
                                            <RowDefinition/>
                                            <RowDefinition/>
                                        </Grid.RowDefinitions>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition/>
                                            <ColumnDefinition/>
                                            <ColumnDefinition/>
                                            <ColumnDefinition/>
                                            <ColumnDefinition/>
                                        </Grid.ColumnDefinitions>
                                        <Ellipse  Grid.Row="0" Grid.Column="2" x:Name="Ellipse0" MinWidth="1" MinHeight="1" Fill="DarkGreen"/>
                                        <Ellipse  Grid.Row="2" Grid.Column="4" x:Name="Ellipse2" MinWidth="1" MinHeight="1" Fill="DarkGreen"/>
                                        <Ellipse  Grid.Row="4" Grid.Column="2" x:Name="Ellipse4" MinWidth="1" MinHeight="1" Fill="DarkGreen"/>
                                        <Ellipse  Grid.Row="2" Grid.Column="0" x:Name="Ellipse6" MinWidth="1" MinHeight="1" Fill="DarkGreen"/>
                                    </Grid>
                                </Grid>
                                <ContentPresenter ContentTemplate="{TemplateBinding BusyContentTemplate}" HorizontalAlignment="Center" VerticalAlignment="Center" Content="{TemplateBinding BusyContent}" Margin="8"/>
                            </Grid>
                        </ContentPresenter>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>
